/*
* Copyright (C) Microsoft. All rights reserved.  
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not 
* use this file except in compliance with the License.  You may obtain a copy 
* of the License at http://www.apache.org/licenses/LICENSE-2.0  
* 
* THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
* WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
* MERCHANTABLITY OR NON-INFRINGEMENT. 
*
* See the Apache License, Version 2.0 for specific language governing 
* permissions and limitations under the License.
*
*/

#pragma once

#include <db/db_index_definition.h>
#include <db/db_tuple_values.h>
#include <db/db_index_field_instance.h>

namespace test_wrappers { namespace storage {

class select_criteria;

class index_instance :
    public std::enable_shared_from_this<index_instance>
{
public:
    // instantiation
    friend std::_Ref_count_obj<index_instance>;
    static std::shared_ptr<index_instance> create(
        const index_definition& indexDefinition,
        const std::shared_ptr<tuple_instance>& tupleInstance);

    // getters
    field_id userIndexId() const;
    std::wstring name() const;
    bool primary() const;
    bool unique() const;

    const std::vector<index_field_instance>& indexFields() const;

    // operations
    const select_criteria createSelectCriteria(
        const comparison_operator& comparisonOperator
        );

private:
    field_id _userIndexId;
    std::wstring _name;
    bool _primary;
    bool _unique;
    std::vector<index_field_instance> _indexFields;
    std::shared_ptr<tuple_instance> _tupleInstance;

    // This class need to be instatiated as a shared object because it
    // needs to pass a pointer to the instance to the select_criteria object.
    // We need this to be ref counted.
    index_instance(
        const index_definition& indexDefinition,
        const std::shared_ptr<tuple_instance>& tupleInstance);
    
    tuple_values index_instance::createValues();
};

}}// namespace test_wrappers::storage
